
class CallStore {
  map = {};
  apiMap;
  constructor(apiMap: any) {
    this.apiMap = apiMap;
    Object.keys(apiMap).forEach(apiName => this.map[apiName] = {});
  }
  call(apiName: string, params: { id: number; }) {
    const {map, apiMap} = this;
    const strParams = JSON.stringify(params);
    if (map[apiName]) {
      return map[apiName][strParams] 
        ? JSON.parse(JSON.stringify(map[apiName][strParams])) 
        : map[apiName][strParams] = apiMap[apiName](...params);
    } else {
      console.error('api: ', apiName, 'isn\'t exist.')
    }
  }
}

/*
*/

const apiMap = {
  getUserList: (groupId: any) => {
    // return get('/api/get/userList', { groupId })
  },
  getTest(id: any) {
    console.log('test is run');
    return {
      test: id,
    }
  }
}

const callStore = new CallStore(apiMap);
callStore.call('getTest', { id: 1 });
callStore.call('getTest', { id: 1 });
callStore.call('getTest', { id: 1 });
callStore.call('getTest', { id: 1 });